/************** O T T R   C O P Y R I G H T   N O T I C E **************
 **                                                                   **
 ** © 2013 OTTR, Inc.  All rights reserved.                           **
 **                                                                   ** 
 *************** O T T R   C O P Y R I G H T   N O T I C E *************/

package com.jonathan.javatar;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 *
 * @author Jonathan Paz <jonathan.paz@ottr.com>
 */
public class TarOutputStream extends FilterOutputStream {
    private boolean closed;

    public TarOutputStream(OutputStream out) {
        super(out);
    }
    
    private void ensureOpen() throws IOException {
        if (closed) {
            throw new IOException("The stream is closed");
        }
    }

    public void putNextEntry(TarEntry e) throws IOException {
        ensureOpen();
    }

    public void closeEntry() throws IOException {
        ensureOpen();
    }

    @Override
    public void close() throws IOException {
        if (!closed) {
            super.close(); //To change body of generated methods, choose Tools | Templates.
            closed = true;
        }
    }
}
